package com.wwl.cms.utils;

import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/12/8 15:12
 * @description:布隆过滤器使用
 */
@Slf4j
public class BloomFilter {
    public static void main(String[] args) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://106.55.187.121:6379");
        //构造Redisson
        RedissonClient redisson = Redisson.create(config);
        RBloomFilter<String> bloomFilter = redisson.getBloomFilter("bloom");
        //初始化布隆过滤器：预计元素1000000L，误判率1%
        bloomFilter.tryInit(1000000L,0.01);
        bloomFilter.add("1");//添加数据
        //判断指定编号是否在布隆过滤器种
        log.info("输出结果：{}",bloomFilter.contains("1"));
        log.info("输出结果：{}",bloomFilter.contains("88"));
    }
}
